package main

import (
	"fmt"
	"strconv"
)

// strconv 用于字符串与数字之间的转换
func main() {
	//v1, _ := decimal.NewFromFloat(9.824).Round(2).Float64()
	//v2, _ := decimal.NewFromFloat(9.826).Round(2).Float64()
	//v3, _ := decimal.NewFromFloat(9.8251).Round(2).Float64()
	//vv1 :=decimal.NewFromFloat(9.824)
	//vv2 :=decimal.NewFromFloat(9.8251)
	//
	//v4,_:=decimal.Sum(vv1,vv2).Round(2).Float64()
	//fmt.Println(v1, v2, v3)
	//fmt.Println(v4)
	//
	//v4, _ := decimal.NewFromFloat(9.815).Round(2).Float64()
	//v5, _ := decimal.NewFromFloat(9.825).Round(2).Float64()
	//v6, _ := decimal.NewFromFloat(9.835).Round(2).Float64()
	//v7, _ := decimal.NewFromFloat(9.845).Round(2).Float64()
	//fmt.Println(v4, v5, v6, v7)
	//
	//v8, _ := decimal.NewFromFloat(3.3).Round(2).Float64()
	//v9, _ := decimal.NewFromFloat(3.3000000000000003).Round(2).Float64()
	//v10, _ := decimal.NewFromFloat(3).Round(2).Float64()
	//fmt.Println(v8, v9, v10)
	//
	//v11, _ := decimal.NewFromFloat(129.975).Round(2).Float64()
	//v12, _ := decimal.NewFromFloat(34423.125).Round(2).Float64()
	//fmt.Println(v11, v12)
	//
	value, err := strconv.ParseFloat(fmt.Sprintf("%.2f", 9.824), 64)
	if err != nil {
		fmt.Println("字符串转换错误！")
	} else {
		fmt.Println(value) //9.82
	}

}

//// 输出如下：
//9.82 9.83 9.83
//9.82 9.83 9.84 9.85
//3.3 3.3 3
//129.98 34423.13
